/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Modelo;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author -ADMIN-
 */
public class Conexion {
    
        
    protected static Connection con = null;
    private static String url = "jdbc:mysql://localhost:3306/designprol?zeroDateTimeBehavior=convertToNull";
    private static String user = "root";
    private static String pass = "";
     private static void conectar(){
         
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection(url,user,pass);
        } catch (ClassNotFoundException | SQLException ex) {
            ex.getMessage();
        }
     }
    
    
    public synchronized static Connection getInstance(){
        if(con ==  null){
           conectar();
        }
        return con;
    }
    
     public static synchronized void cerrarCall(CallableStatement cl) {
        try{cl.close();}catch(SQLException e){}
    }
     
    //Metodo utilizado para cerrar el resulset de datos
    public static synchronized void cerrarConexion(ResultSet rs) {
        try{rs.close();} catch (SQLException e) {}
    }
    
    //Metodo utilizado para cerrar la conexion
    public static synchronized void cerrarConexion(Connection cn) {
        try{
            cn.close();
            con = null;
        } catch (SQLException e) {
            throw new RuntimeException("error al cerrar la conexion: "+e);
        }
    }
    
    //Metodo utilizado para deshacer los cambios en la base de datos
    public static synchronized void deshacerCambios(Connection cn) {
        try{
           cn.rollback();
        }catch (SQLException e){
            throw  new RuntimeException("error al deshacer accion: "+e);
        }
    }
    
//     
//    public void cerrarConexion(){
//        con = null;
//    }
    

}
